package com.briup.sms.web.controller;

import com.briup.sms.entity.Order;
import com.briup.sms.service.OrderService;
import com.briup.sms.utils.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author :xuyang
 * @DateTime:2024/1/11 21:25
 * @Version :v1.0.0
 * ClassName:OrderController
 * Package  :com.briup.sms.web.controller
 * Description:TODO
 */
@RestController
@RequestMapping("/order")
@Api(tags = "订单管理")
@CrossOrigin
public class OrderController {
    @Autowired
    OrderService service;

    @GetMapping("/getOrderInfo")
    @ApiOperation("订单信息筛选")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "orderId", value = "订单编号"),
                    @ApiImplicitParam(name = "status", value = "订单状态"),
                    @ApiImplicitParam(name = "pageSize", value = "分页每页数据条数", required = true),
                    @ApiImplicitParam(name = "pageNum", value = "页码", required = true)
            }
    )
    public Result getOrderInfo(String orderId, Boolean status, Integer pageSize, Integer pageNum) {
        PageInfo<Order> orders = service.getOrderInfo(orderId, status, pageSize, pageNum);
        return Result.success(orders);
    }

    @PostMapping("/updateOrder")
    @ApiOperation("订单修改")
    public Result save(@RequestBody Order order) {
        service.updateOrder(order);
        return Result.success();
    }

    @GetMapping("/getOrder/{id}")
    @ApiOperation("查询订单详情")
    public Result getOrder(@PathVariable String id) {
        Order order = service.getOrder(id);
        return Result.success(order);
    }
}

